home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / 8Bawl.bproj / 8Bawl.m < prev    next >
Encoding:
Text File  |  1994-11-01  |  7.8 KB  |  243 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    8Bawl.m
  3. //    SUMMARY:    an Eight-Ball (TM) Annotation
  4. //    SUPERCLASS:    Object
  5. //    INTERFACE:    None
  6. //    PROTOCOLS:    <Annotation, Tool>
  7. //    AUTHOR:        Eric P. Scott, ported to eText by Rohit Khare
  8. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  9. //    COPYRIGHT:    (c) 1994 San Francisco State University
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //    DESCRIPTION
  12. //        An example of how to port over a simple View-based widget. Original
  13. //    application and 8Bawl source code by Eric P. Scott, Tech alum @ SFSU
  14. ///////////////////////////////////////////////////////////////////////////////
  15. //             BawlApp.m: a toy for the virtual desktop
  16. //             Eric P. Scott, San Francisco State University, January 1994
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //    HISTORY
  19. //    05/22/94:    Created. First eText port.
  20. ///////////////////////////////////////////////////////////////////////////////
  21.  
  22. #import "eTextKernel.h"
  23. #include "wraps8.h"
  24. #include <bsd/libc.h>
  25.  
  26. #define    NIMAGES 21
  27. @class EBI;
  28.  
  29. // File-Scope Global shared by all 8Bawls
  30. id    face[NIMAGES];
  31. id    base8;
  32. id    big8;
  33. BOOL initted=NO;
  34.  
  35.  
  36. @interface EightBawl:Object <Annotation, Tool>
  37. {    BOOL    highlighted;
  38.     int        animStep;
  39.     id        cimage;
  40.     NXRect  savedFrame;
  41.     NXPoint savedPoint;
  42. }
  43. @end
  44.  
  45. @implementation EightBawl
  46.  
  47. const NXRect bigRect={ { 0.0, 0.0 }, { 288.0, 288.0 } };
  48. const NXPoint smallRectOrigin={ 96.0, 88.0}, smallRectUpOrigin={ 96.0, 116.0};
  49. const NXSize smallRectSize={ 96.0, 84.0};
  50.  
  51. + toolAwake:theApp
  52. {
  53.     long         now;
  54.     int         i;
  55.     char        buf[MAXPATHLEN];
  56.     NXBundle    *bundle;
  57.     
  58.     (void)time(&now);
  59.     srandom((int)now^(0xffffff));
  60.     if (!initted) {
  61.     for(i=0; i < NIMAGES; i++) face[i] = nil;
  62.     bundle = [NXBundle bundleForClass:[EightBawl class]];
  63.     if ([bundle getPath:buf forResource:"Base8" ofType:"eps"] )
  64.         base8 = [[NXImage alloc] initFromFile:buf];
  65.     if ([bundle getPath:buf forResource:"Big8" ofType:"eps"] )
  66.         big8 = [[NXImage alloc] initFromFile:buf];
  67.     if ([bundle getPath:buf forResource:"small8" ofType:"tiff"] )
  68.         face[0] = [[NXImage alloc] initFromFile:buf];
  69.     if ([bundle getPath:buf forResource:"ask_again" ofType:"tiff"] )
  70.         face[1] = [[NXImage alloc] initFromFile:buf];
  71.     if ([bundle getPath:buf forResource:"as_i_see_it" ofType:"tiff"] )
  72.         face[2] = [[NXImage alloc] initFromFile:buf];
  73.     if ([bundle getPath:buf forResource:"better_not" ofType:"tiff"] )
  74.         face[3] = [[NXImage alloc] initFromFile:buf];
  75.     if ([bundle getPath:buf forResource:"certain" ofType:"tiff"] )
  76.         face[4] = [[NXImage alloc] initFromFile:buf];
  77.     if ([bundle getPath:buf forResource:"cannot_predict" ofType:"tiff"] )
  78.         face[5] = [[NXImage alloc] initFromFile:buf];
  79.     if ([bundle getPath:buf forResource:"concentrate" ofType:"tiff"] )
  80.         face[6] = [[NXImage alloc] initFromFile:buf];
  81.     if ([bundle getPath:buf forResource:"decidedly" ofType:"tiff"] )
  82.         face[7] = [[NXImage alloc] initFromFile:buf];
  83.     if ([bundle getPath:buf forResource:"may_rely" ofType:"tiff"] )
  84.         face[8] = [[NXImage alloc] initFromFile:buf];
  85.     if ([bundle getPath:buf forResource:"outlook_good" ofType:"tiff"] )
  86.         face[9] = [[NXImage alloc] initFromFile:buf];
  87.     if ([bundle getPath:buf forResource:"definitely" ofType:"tiff"] )
  88.         face[10] = [[NXImage alloc] initFromFile:buf];
  89.     if ([bundle getPath:buf forResource:"outlook_not" ofType:"tiff"] )
  90.         face[11] = [[NXImage alloc] initFromFile:buf];
  91.     if ([bundle getPath:buf forResource:"reply_hazy" ofType:"tiff"] )
  92.         face[12] = [[NXImage alloc] initFromFile:buf];
  93.     if ([bundle getPath:buf forResource:"dont_count" ofType:"tiff"] )
  94.         face[13] = [[NXImage alloc] initFromFile:buf];
  95.     if ([bundle getPath:buf forResource:"reply_no" ofType:"tiff"] )
  96.         face[14] = [[NXImage alloc] initFromFile:buf];
  97.     if ([bundle getPath:buf forResource:"signs_point" ofType:"tiff"] )
  98.         face[15] = [[NXImage alloc] initFromFile:buf];
  99.     if ([bundle getPath:buf forResource:"doubtful" ofType:"tiff"] )
  100.         face[16] = [[NXImage alloc] initFromFile:buf];
  101.     if ([bundle getPath:buf forResource:"sources_say" ofType:"tiff"] )
  102.         face[17] = [[NXImage alloc] initFromFile:buf];
  103.     if ([bundle getPath:buf forResource:"without_doubt" ofType:"tiff"] )
  104.         face[18] = [[NXImage alloc] initFromFile:buf];
  105.     if ([bundle getPath:buf forResource:"most_likely" ofType:"tiff"] )
  106.         face[19] = [[NXImage alloc] initFromFile:buf];
  107.     if ([bundle getPath:buf forResource:"yes" ofType:"tiff"] )
  108.         face[20] = [[NXImage alloc] initFromFile:buf];
  109.     initted = YES;
  110.     }
  111.     [theApp   registerAnnotation: [EightBawl class] 
  112.                             name: "EightBawl"
  113.                     RTFDirective: "EightBawl"
  114.                        menuLabel: "Fun Stuff/Consult 8Bawl..."
  115.                          menuKey: '\0'
  116.                         menuIcon: (NXImage *) face[0]];
  117.     return self;
  118. }
  119.  
  120. - init
  121. {
  122.     cimage = [[NXImage alloc] initSize:&smallRectSize];
  123.     [cimage setUnique:YES];    // this image must stay opaque!
  124.     [cimage setBackgroundColor:NX_COLORWHITE];
  125.     [cimage useCacheWithDepth:NX_DefaultDepth];
  126.     return self;
  127. }
  128.  
  129. - free
  130. {
  131.     [[NXApp inspector] invalidate];
  132.     return [super free];
  133. }
  134.  
  135. - initFromPboard:thePB inDoc:theDoc linked:(BOOL) linked {return [self init];}
  136.  
  137. // drawing loops -- trackMouse
  138. - anim:controlView
  139. {
  140.     
  141.     [controlView lockFocus];
  142.     PSgsave();
  143.     if (animStep == 5) {
  144.         NXPoint point;
  145.         
  146.         PSsetgray([controlView backgroundGray]);
  147.         NXRectFill(&savedFrame);
  148.         point = savedFrame.origin;
  149.         point.y += savedFrame.size.height;
  150.         [big8 composite:NX_SOVER toPoint:&point];
  151.     } else {
  152.         [cimage dissolve:((++animStep) * .2) toPoint:&savedPoint];
  153.         [self perform:@selector(anim:) with:controlView afterDelay:1000 cancelPrevious:NO];
  154.     }
  155.     PSgrestore(); 
  156.     [controlView unlockFocus];
  157.     DPSFlush();
  158.     NXPing();
  159.     return self;
  160. }
  161.  
  162. - (BOOL)    trackMouse:(NXEvent *)event
  163.             inRect:(const NXRect *)cellFrame
  164.             ofView:controlView    
  165. {
  166.     const NXPoint zero={ 0.0, 0.0 };
  167.     NXRect cr;
  168.     NXPoint    point;
  169.     int k;
  170.  
  171.     [[NXApp inspector] inspect:[EBI new]];    
  172.     PSgsave();
  173.     PSobscurecursor();
  174.     PSsetwaitcursorenabled(NO);    // cheating!
  175.     if (highlighted) PSsetgray(NX_LTGRAY);
  176.     else PSsetgray([controlView backgroundGray]);
  177.     NXRectFill(cellFrame);
  178.     PSgrestore();
  179.     point = cellFrame->origin;
  180.     point.y += cellFrame->size.height;
  181.     [base8 composite:NX_SOVER toPoint:&point];
  182.     point.x += smallRectOrigin.x;
  183.     k = (int)(random()&0x7fffffff)%(NIMAGES-1) + 1;
  184.     if ((k-1)%3 == 0) point.y -= smallRectUpOrigin.y;
  185.     else point.y -= smallRectOrigin.y;
  186. //    dissolve base8 up to face[k]    
  187.     [cimage lockFocus];
  188.     cr.size = smallRectSize;
  189.     cr.origin=((k-1)%3 == 0) ? smallRectUpOrigin : smallRectOrigin;
  190.     [base8 composite:NX_SOVER fromRect:&cr toPoint:&zero];
  191.     [face[k] composite:NX_SOVER toPoint:&zero];
  192.     [cimage unlockFocus];
  193.     
  194.     animStep = 0;
  195.     savedPoint = point;
  196.     savedFrame = *cellFrame;
  197.     [self perform:@selector(anim:) with:controlView afterDelay:1000 cancelPrevious:NO];
  198.     
  199. //    for (dpt = 0.1; dpt < 1.0; dpt += .1){
  200. //        [cimage dissolve:dpt toPoint:&point];
  201. //        DPSFlush();
  202. //        [[controlView window] flushWindow];
  203. //        NXPing();
  204. //    }
  205. //    dissolve face[k] down to big8
  206.     PSgsave();
  207. //    PSsetgray([controlView backgroundGray]);
  208. //    NXRectFill(cellFrame);
  209. //    point = cellFrame->origin;
  210. //  point.y += cellFrame->size.height;
  211. //    [big8 composite:NX_SOVER toPoint:&point]; 
  212. //    [cimage composite:NX_SOVER toPoint:&point];
  213.  
  214.     PSgrestore();
  215.     PSsetwaitcursorenabled(YES);
  216.     return YES;
  217. }
  218. // default drawSelf
  219. - drawSelf:(const NXRect *)cellFrame inView:view
  220. {
  221.     NXPoint    point;
  222.     
  223.     PSgsave();
  224.     if (highlighted) PSsetgray(NX_LTGRAY);
  225.     else PSsetgray([view backgroundGray]);
  226.     NXRectFill(cellFrame);
  227.     
  228.     point = cellFrame->origin;
  229.     point.y += cellFrame->size.height;
  230.     [big8 composite:NX_SOVER toPoint:&point];
  231.     PSgrestore();
  232.     return self;
  233. }
  234.  
  235. - calcCellSize:(NXSize *)theSize 
  236.     {theSize->width = theSize->height = 288.0; return self;}
  237. - highlight:(const NXRect *)rect inView:view lit:(BOOL)flag
  238.     {highlighted = !highlighted; NXHighlightRect(rect);return self;}
  239. - readRichText:(NXStream *)stream forView:view 
  240.     {return self;}
  241. - writeRichText:(NXStream *)stream forView:view
  242.     {return self;}
  243. @end